import React, { PureComponent } from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'react-redux';

class Content extends PureComponent
{
    constructor(props)
    {
        super(props);
        this.state = {
        };
    }
    render()
    {
        return (
            <div className="appContent" style={{height: this.state.height ? (this.state.height + 'px') : '100%', ...this.props.style}}>{this.props.children}</div>
        );
    }
    componentDidMount()
    {
        const height = window.innerHeight - ReactDOM.findDOMNode(this).parentNode.offsetTop;
        this.setState({height: height});
    }
    componentDidUpdate(prevProps, prevState, snapshot)
    {
        if(this.props.height)
        {
            let height = window.innerHeight - ReactDOM.findDOMNode(this).parentNode.offsetTop;
            if(height !== this.state.height)
            {
                this.setState({height});
            }
        }
    }
    getOffsetY()
    {
        return ReactDOM.findDOMNode(this).scrollTop;
    }
    scrollToY(offsetY)
    {
        // ReactDOM.findDOMNode(this).scrollTo(0, offsetY);
        let v = ReactDOM.findDOMNode(this);
        if(v)
        {
            v.scrollTop = offsetY;
        }
    }
}


const mapStateToProps = function(state, ownProps)
{
    // let obj = state.native.windowSize;
    return {
        // ...obj,
    };
};

Content = connect(mapStateToProps, null, null, {withRef: true})(Content);

export default Content;